The present invention relates to integrated development environment (IDE) tools, and more specifically, to managing code assertions in a source code component when compiling and debugging source code in a development project.
Assertions are small segments of source code used to help debug a computer program. An assertion specifies a condition used to test whether a program functions correctly when executed. Typically, if the condition in an assertion evaluates to true, then the program is presumed to be functioning correctly (at least relative to the condition specified in the assertion). In such a case, the assertion does not interfere with program execution, apart from the overhead of testing the condition. However, if the condition in an assertion evaluates to false, the assertion could terminate the program, allow program execution to continue unhindered, throw an exception, or allow a user to choose how to proceed.
Typically, developers manually include, edit, and remove assertions from source code while developing an application. As developers use assertions to test source code, developers will typically remove assertions from source code during the development process once code is believed to be functioning correctly. For example, one approach is to turn assertions “on” or “off” using compiler preprocessing statements, e.g., ifdef expressions.
Assertions vary in complexity and the time required to be executed. A simple assertion, such as checking the value of a variable (e.g., “assert (i>0)”) may have a minimal impact on processing. More complex assertions, such as determining whether the elements of a linked list are in a particular order may require relatively large amounts of processing time. Because processing assertions adds overhead to program execution time, it may be desirable to remove some assertions before compiling source code into program code.
However, as developers revise source code, some assertions may be useful to help identify and resolve defects.